home *** CD-ROM | disk | FTP | other *** search
- /* setusrsz.c --- setusercharsize */
- /* copied from Turbo C Bible, page 859-861 */
- #include <graphics.h>
- char long_title[]=
- {"This title has been scaled to fit inside this box"};
- main()
- {
- int graphdriver = DETECT, graphmode,xmax,ymax,xsize,ysize,
- textx,texty,multx,multy,divx,divy;
- double ratio;
- /* Detect and initialize graphics system */
- initgraph(&graphdriver, &graphmode, "c:\\turboc");
- /* Define a viewport */
- xmax = getmaxx();
- ymax = getmaxy();
- xsize = xmax - 100;
- ysize = ymax/5;
- setviewport(50, 30, xsize+50, ysize+30, 1);
- setfillstyle(SOLID_FILL, RED);
- bar3d(0,0,xsize,ysize,0,1);
- setcolor(YELLOW);
- settextjustify(CENTER_TEXT,CENTER_TEXT);
- /* Define the scaling necessary to fit title in box.
- * The integers fed to setusercharsize must not be
- * large. For example,
- * setusercharsize(500,750,1,1) fails to scale. */
- settextstyle(TRIPLEX_FONT,HORIZ_DIR,0);
- setusercharsize(1,1,1,1);
- textx = textwidth(long_title);
- texty = textheight(long_title);
- /* If title fits, leave it untouched */
- if(textx < xsize)
- {
- multx = 1;
- divx = 1;
- }
- else
- {
- ratio = 10.*(double)xsize/(double)textx;
- multx = (int)ratio;
- divx = 1;
- }
- if (texty < ysize)
- {
- multy = 1;
- divy = 1;
- }
- else
- {
- ratio = 10.*(double)ysize/(double)texty;
- multy = (int)ratio;
- divy = 10;
- }
- /* Now set scale and print title */
- setusercharsize(multx,divx,multy,divy);
- settextstyle(TRIPLEX_FONT, HORIZ_DIR, 0);
- outtextxy(xsize/2,ysize/2, long_title);
- /* Wait for a key press. */
- getch();
- /* Close graphics system when done */
- closegraph();
- }